import req from './../../../fetch'; import { undocumentedResponse } from './../../../utils'; import { AliasChannelType, AllAPIResponses, CarbonError, } from './../../../index'; import { PostPayload } from '../.'; type Params = { id: number; }; const put = async ( params: Params, payload: Partial, headers?: Headers ): Promise> => { const resp = await req.put( `/api/aliaschannels/${params.id}`, JSON.stringify(payload), headers ); try { const clone = resp.clone(); switch (resp.status) { case 200: return { data: (await resp.json()) as AliasChannelType, response: clone, }; case 400: case 401: case 403: case 404: case 500: return { error: (await resp.json()) as CarbonError, response: clone, }; default: return { error: new Error(undocumentedResponse(resp)), response: clone, }; } } catch (e) { return { error: e, response: undefined }; } }; export default put;